﻿using EkejiWeb.BLL;
using EkejiWeb.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace EkejiWeb.Web.Admin.Operations
{
    public partial class OperationsPublish : System.Web.UI.Page
    {
        //<%=Session["tbName"].ToString()%>
        string path = "";
        string picturename = "";

        OperationsBLL operationsbll = new OperationsBLL();
        OperationsModel operationsmodel = new OperationsModel();
        protected void Page_Load(object sender, EventArgs e)
        {
            int adminAdminId = int.Parse(Session["AdminId"].ToString());
            string UserName = operationsbll.SelectUserNameByID(adminAdminId);
            tbUserName.Text = UserName;
        }

        //protected void btnFile_Click(object sender, EventArgs e)
        //{
        //    path = MapPath("/Admin/files/Operations/");//设置图片存储的路径
        //    picturename = Guid.NewGuid().ToString() + ".png";//设置图片的名称
        //    fupPicture.SaveAs(path + picturename);
        //}

        protected void btnPub_Click(object sender, EventArgs e)
        {
            path = MapPath("/Admin/files/Operations/");//设置图片存储的路径
            picturename = Guid.NewGuid().ToString() + ".png";//设置图片的名称
            fupPicture.SaveAs(path + picturename);

            bool flag = false;
            operationsmodel.Title = tbTitle.Text.Trim();
            operationsmodel.Message = tbMessage.Text.Trim();
            operationsmodel.PublishId = int.Parse(Session["AdminId"].ToString());
            operationsmodel.PublishTime = tbTime.Text.Trim();
            operationsmodel.FilePath = "/Admin/files/Operations/" + picturename;

            flag = operationsbll.Add(operationsmodel);
            if (flag)
            {
                Response.Write("<Script Language=JavaScript>alert('发布成功！');</Script>");
                return;
            }
            else
            {
                Response.Write("<Script Language=JavaScript>alert('发布失败！');</Script>");
                return;
            }
        }
    }
}